/* 
路由器对象
*/
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home'
import Login from '@/views/Login'
import Course from '@/views/Home/components/Course'
import Game from '@/views/Home/components/Game'
import News from '@/views/Home/components/News'
import CourseItem from '@/views/Home/components/Course/Item'

// 安装插件
Vue.use(VueRouter)

// 创建路由器对象
const router = new VueRouter({
  // 路由表
  routes: [
    // 路由 path component
    {name: 'Login', path: '/login', component: Login},
    {
      name: 'Home',
      path: '/home', 
      component: Home,
      // 写法2: 当访问/home时, 自动跳转到/home/course
      redirect: '/home/course',
      // 注册二级子路由
      children: [
        {name: 'News', path: '/home/news', component: News},
        {name: 'Game', path: 'game', component: Game},
        {
          name: 'Course', 
          path: 'course', 
          component: Course,
          children: [
            {
              name: 'CourseItem', 
              path: 'item/:id/:name',   // 必须要有冒号占位
              component: CourseItem
            }
          ]
        },
        // 写法一: 当访问/home时, 自动跳转到/home/course
        // {path: '', redirect: '/home/course'},

      ]
    },
    // 当请求项目根路径时, 自动跳转/login路由路径
    {
      path: '/',
      redirect: '/home'
    }
  ]
})
// 暴露路由器
export default router
